package be.gnx.log4jeclipse.perspective.view;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.action.IContributionManager;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.part.ViewPart;

import be.gnx.log4jeclipse.log4j.Log4JListener;
import be.gnx.log4jeclipse.log4j.Log4JListenerCallbacks;
import be.gnx.log4jeclipse.perspective.action.StartStopServerAction;

public class Log4JEclipseView extends ViewPart implements Log4JListenerCallbacks {

  private StartStopServerAction startStopServerAction;

  private boolean serverRunning = false;

  @Override
  public void createPartControl(Composite parent) {
    Log4JListener.getInstance().addLog4JListenerCallBacks(this);
    startStopServerAction = new StartStopServerAction(this);
    IActionBars bars = getViewSite().getActionBars();
    addActions(bars.getMenuManager());
    addActions(bars.getToolBarManager());
  }

  @Override
  public void setFocus() {
    // TODO Auto-generated method stub

  }

  private void addActions(IContributionManager manager) {
    manager.add(startStopServerAction);
  }

  public boolean isServerRunning() {
    return serverRunning;
  }

  public List<PortBacklogInetaddress> getPortBacklogInetaddressList() {
    List<PortBacklogInetaddress> portBacklogInetaddresList = new ArrayList<PortBacklogInetaddress>();
    portBacklogInetaddresList.add(new PortBacklogInetaddress(4445));
    return portBacklogInetaddresList;
  }

}
